﻿namespace EasyGo.Models
{
    using System.Web.Mvc;

    using Newtonsoft.Json;

    public class JsonResponse
    {
        public JsonResponse(bool success = true, object data = null)
        {
            this.Success = success;
            this.Response = data;
        }

        public bool Success { get; set; }

        public object Response { get; set; }

        public string Error { get; set; }

        public ActionResult ToActionResult()
        {
            var result = new ContentResult();
            result.Content = JsonConvert.SerializeObject(this);
            result.ContentType = "application/json";
            return result;
        }

        public void Fail(string message)
        {
            this.Success = false;
            this.Error = message;
        }
    }
}